package logic

import (
	"context"
	"video-hub/videorpc/videorpc"

	"video-hub/api/internal/svc"
	"video-hub/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdatePasswordLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdatePasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePasswordLogic {
	return &UpdatePasswordLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdatePasswordLogic) UpdatePassword(req *types.UpdatePasswordRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	add, err := l.svcCtx.VideoRpc.UpdatePassword(l.ctx, &videorpc.UpdatePasswordRequest{
		PhoneNum: req.PhoneNum,
		SmsCode:  req.SmsCode,
		OldPwd:   req.OldPwd,
		NewPwd:   req.NewPwd,
		CurePwd:  req.CurePwd,
		NickName: req.NickName,
	})
	if err != nil {
		return &types.Response{
			Message: "修改失败",
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "修改成功",
		Code:    200,
		Data:    add,
	}, nil
}
